<template>
    <div class="environment-grid">
        <div class="env-item" v-for="item in environment" :key="item.id">
        <div class="env-icon" :class="getEnvIconClass(item.compName)">
            <i class="el-icon-sunny" v-if="item.compName == '温度'"></i>
            <i class="el-icon-heavy-rain" v-if="item.compName == '降雨量'"></i>
            <i class="iconfont" v-if="item.compName == '水位'">&#xe776;</i>
            <i class="iconfont" v-if="item.compName == '出入库流量'">&#xe731;</i>
        </div>
        <div class="env-info">
            <div class="value">{{ item.compValue }}{{ item.unit }}</div>
            <div class="label">{{ item.pointName }}</div>
        </div>
        </div>
    </div>
</template>
<script>

export default ({
    props:{
        environment:{
            type:Array,
            default:()=>{
                return []
            }
        }
    },
    data() {
        return{

        }
    },
    methods:{
        getEnvIconClass(compName) {
            const iconMap = {
            '温度': 'temperature',
            '降雨量': 'rainfall',
            '水位': 'water',
            '出入库流量': 'flow'
            };
            return iconMap[compName] || '';
        },
    }
})
</script>

<style scoped lang="scss">
.environment-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 10px;

    .env-item {
        display: flex;
        align-items: center;
        padding: 15px;
        background: #f9fafc;
        border-radius: 8px;
    
        .env-icon {
            display: flex;
            align-items: center;
            justify-content: center;
            width: 40px;
            height: 40px;
            border-radius: 8px;
            margin-right: 15px;
            font-size: 20px;
        
            &.temperature {
                background: #fff2e8;
                color: #fa541c;
            }
            
            &.rainfall {
                background: #e3f1ea;
                color: #1890ff;
            }
            
            &.water {
                background: #f0f9ff;
                color: #1890ff;
                i{
                font-size: 20px;
                }
            }
            
            &.flow {
                background: #fafff1;
                color: #7ace4f;
                i{
                font-size: 20px;
                }
            }
        }
        
        .env-info {
            .value {
                font-size: 18px;
                font-weight: 700;
                color: #303133;
                width:106px;
                text-overflow: ellipsis;
                overflow: hidden;
                height: 24px;
            }
            
            .label {
                font-size: 13px;
                color: #909399;
            }
        }
    }
}
</style>